$(function (){
    let adminFile;
    $("#doc").change(function (event) {
        // 检查是否已选择视频文件
        if (!this.files || !this.files[0]) {
            return;
        }
        // 获取选中的文件信息
        let file = this.files[0];
        adminFile = file;
        let fileName = file.name;
        let fileSize
            = file.size;
        let fileType = file.type;
        console.log(adminFile)
        if (fileType.indexOf('image/') === 0 && fileSize < 500 * 1024 * 1024) {

        }else{
            // 将文件信息显示在页面上
            alert('请选择图片文件，且文件大小不能超过500MB！');
        }
    });

    $(".update").on("click",function (){
        const set =new Set();
        const informationId=$(".administrator-text-from").attr("information-id")
        const name=$(".administrator-name-text").val()
        let avatar=$(".avatar-btn-img").val().substring(12)
        if(""===avatar){
            avatar="admin.png";
        }
        const phone=$(".phone").val()
        const signature=$(".signature").val()
        const sex=$(".sex").val()
        const mailbox=$(".mailbox").val()
        const sparePhone=$(".spare-phone").val()
        const homeAddress=$(".home-address").val()
        const contact=$(".contact").val()
        const contactPhone=$(".contact-phone").val()
        const administratorId=$(".administrator-id-text").val()
        const dateBirth=$(".date-birth").val()
        const departmentId=$(".department-id").val()
        let commodity = new Commodity();
        commodity.addCommodityImage(adminFile).then(function (response) {
            set.administratorInformationUpdate(name,phone,mailbox,informationId,sparePhone,homeAddress,contact,signature,contactPhone,sex,response,administratorId,dateBirth,departmentId).then(res => {
                //location.reload();
            })
        });
    })

    const img=$(".avatar-img").attr("img")
    $(".avatar").on({
        mouseenter: function () {
            $(".avatar-img").attr({"src": "http://localhost:8083/resource_packs/images/camera.png"})
        }, mouseleave: function () {
            $(".avatar-img").attr({"src": "http://localhost:8083/resource_packs/images/"+img})
        }
    });
    $(".avatar").on("click",function (){
        $(".hint-window-logout").css("display","block")
    })
    let hintImg = $(".hint-img");
    hintImg.on("click",function (){
        $(".hint-window-logout").css("display","none")
    })
    hintImg.on({
        mouseenter: function () {
            hintImg.attr({"src": "http://localhost:8083/resource_packs/images/pop_ups_closes_red.png"})
        }, mouseleave: function () {
            hintImg.attr({"src": "http://localhost:8083/resource_packs/images/pop_ups_closes.png"})
        }
    });


})
